# -*- coding:utf-8 -*-
# @Project:
# @File:
# @Date:
# @Author:Joe
# @Description:

import schedule
import time
import subprocess


def run_pytest():
    """运行pytest，执行测试用例并生成报告"""
    print("Running pytest...")

    # try:
    #     # 执行 anywhere 命令来启动静态文件服务器
    #     process = subprocess.Popen(["anywhere", "-s", "-p", "8000"], cwd="./allure_report", shell=True)
    #     print("1")
    # except Exception as e:
    #     print(e)
    #
    # # 关闭进程
    # process.terminate()
    # print("2")
    #
    # # 等待进程结束
    # process.wait()
    # print("3")

    # 执行 pytest 命令并生成 Allure 报告
    subprocess.run(["pytest", "--alluredir=allure-results", "--clean-alluredir"])

    # 执行 Allure 报告生成命令
    subprocess.run(r'"D:\Program Files\allure-2.30.0\bin\allure" generate "./allure-results" -o "./allure-report" -c', shell=True)

    # 执行 wechat.py 脚本，发送微信通知。
    subprocess.run(["python", "wechat.py"], shell=True)

    # # 执行 anywhere 命令来启动静态文件服务器
    # process = subprocess.Popen(["anywhere", "-s", "-p", "8000"], cwd="./allure_report", shell=True)


# 定义定时任务，例如每天凌晨1点运行
schedule.every().day.at("01:00").do(run_pytest)


while True:
    schedule.run_pending()
    time.sleep(60)  # 检查一次计划任务的间隔时间
# run_pytest()
